<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        //echo 'hellow world';
        $Data = M('form');
        $this->data = $Data->select();
        $this->display();
    }

    //表单提交界面
    public function add(){
        $this->display();
    }

    //插入数据
    public function insert(){
        $Form = D('Form');
        if($Form->create()){
            $result = $Form->add();
            if($result){
                $this->success('操作成功！');
            }else{
                $this->error("写入错误");
            }
        }else{
            $this->error($Form->getError());
        }
    }

    //展示数据
    public function read($id =0){
        $Form = M('Form');
        //读取数据
        $data = $Form ->find($id);
        if($data){
            $this->data = $data;

        }else{
            $this->error('数据错误');
        }
        $this->display();
    }

    //编辑数据
    public function edit($id=0){
        $Form = M('Form');
        $this->vo = $Form->find($id);
        $this->display();
    }

    public function update(){
        $Form = D('Form');
        if($Form->create()){
            $result = $Form->save();
            if($result){
                $this->success('操作成功');
            }else{
                $this->error('写入错误');
            }
        }else{
            $this->error($Form->getError());
        }
    }




}